package org.jeecg.modules.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.dto.BankSetDTO;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.business.mapper.CaishuiCompanySetMapper;
import org.jeecg.modules.business.service.ICaishuiCompanySetService;
import org.jeecg.modules.manage.entity.CaishuiCompanySet;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @Description: 服务公司配置
 * @Author: yfkj
 * @Date:   2023-03-27
 * @Version: V1.0
 */
@Service
public class CaishuiCompanySetServiceImpl extends ServiceImpl<CaishuiCompanySetMapper, CaishuiCompanySet> implements ICaishuiCompanySetService {

    /**
     * 根据账号查询服务公司设置相关信息
     * @param account
     * @return
     */
    @Override
    public BankSetDTO queryCompanySet(String account) {
        CaishuiCompanySet caishuiCompanySet = null;
        try {
            caishuiCompanySet = this.baseMapper.selectOne(new LambdaQueryWrapper<CaishuiCompanySet>()
                    .eq(CaishuiCompanySet::getAccount, account));
            if (oConvertUtils.isEmpty(caishuiCompanySet)) {
                throw new JeecgBootException("暂未设置银行密钥！");
            }

            BankSetDTO bankSetDTO = new BankSetDTO();
            BeanUtils.copyProperties(caishuiCompanySet, bankSetDTO);
            return bankSetDTO;
        } catch (Exception e) {
            log.error("[" + account + "]服务公司设置有误===>：" + e.getMessage());
            throw new JeecgBootException("银行密钥设置有误！");
        }
    }

}